<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="人才id" prop="telnetId">
      <el-input v-model="dataForm.telnetId" placeholder="人才id"></el-input>
    </el-form-item>
    <el-form-item label="学校名称" prop="universityName">
      <el-input v-model="dataForm.universityName" placeholder="学校名称"></el-input>
    </el-form-item>
    <el-form-item label="专业" prop="major">
      <el-input v-model="dataForm.major" placeholder="专业"></el-input>
    </el-form-item>
    <el-form-item label="取的学历" prop="getEducationId">
      <el-input v-model="dataForm.getEducationId" placeholder="取的学历"></el-input>
    </el-form-item>
    <el-form-item label="毕业时间" prop="graduateTime">
      <el-input v-model="dataForm.graduateTime" placeholder="毕业时间"></el-input>
    </el-form-item>
    <el-form-item label="逻辑删除字段" prop="isDeleted">
      <el-input v-model="dataForm.isDeleted" placeholder="逻辑删除字段"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          telnetId: '',
          universityName: '',
          major: '',
          getEducationId: '',
          graduateTime: '',
          isDeleted: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          telnetId: [
            { required: true, message: '人才id不能为空', trigger: 'blur' }
          ],
          universityName: [
            { required: true, message: '学校名称不能为空', trigger: 'blur' }
          ],
          major: [
            { required: true, message: '专业不能为空', trigger: 'blur' }
          ],
          getEducationId: [
            { required: true, message: '取的学历不能为空', trigger: 'blur' }
          ],
          graduateTime: [
            { required: true, message: '毕业时间不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '逻辑删除字段不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/telnets/telneteducationbackground/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.telnetId = data.telnetEducationBackground.telnetId
                this.dataForm.universityName = data.telnetEducationBackground.universityName
                this.dataForm.major = data.telnetEducationBackground.major
                this.dataForm.getEducationId = data.telnetEducationBackground.getEducationId
                this.dataForm.graduateTime = data.telnetEducationBackground.graduateTime
                this.dataForm.isDeleted = data.telnetEducationBackground.isDeleted
                this.dataForm.createTime = data.telnetEducationBackground.createTime
                this.dataForm.updateTime = data.telnetEducationBackground.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/telnets/telneteducationbackground/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'telnetId': this.dataForm.telnetId,
                'universityName': this.dataForm.universityName,
                'major': this.dataForm.major,
                'getEducationId': this.dataForm.getEducationId,
                'graduateTime': this.dataForm.graduateTime,
                'isDeleted': this.dataForm.isDeleted,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
